package com.shangma;

import sun.net.www.protocol.http.HttpURLConnection;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

public class TestDemo {

    public static void main(String[] args) throws IOException {
        String path = "http://api.tianapi.com/networkhot/index?key=94aed0ea1c6e95f25086b8390ad26041";
        //创建URL对象
        URL url = new URL(path);
        HttpURLConnection httpURLConnection = (HttpURLConnection) url.getContent();
        httpURLConnection.connect();
        //获取接口数据,获取字节输入流
        InputStream in = httpURLConnection.getInputStream();
        byte[] bytes = new byte[in.available()];
        in.read(bytes);
        //把字节数组转换成字符串
        String str = new String(bytes);
        System.out.printf(str);


    }
}
